package com.student.controller;


import com.student.VO.UserVO;
import com.student.VO.productPageVO;
import com.student.dto.ResponseDto;
import com.student.pojo.SnackAddress;
import com.student.service.UserService;
import com.student.util.ValidateCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @BelongsProject: makeUp
 * @BelongsPackage: com.student.controller
 * @Author: 小徐
 * @CreateTime: 2024-12-09 21:30
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 生成验证码
     *
     * @return
     */
    @GetMapping("/getCode")
    public ResponseDto getCode() {
        ValidateCodeUtil validateCodeUtil = new ValidateCodeUtil();
        String randomCodeImage = validateCodeUtil.getRandomCodeImage();
        String code = validateCodeUtil.getCode();
        HashMap<Object, Object> map = new HashMap<>();
        map.put("code", code);
        map.put("randomCodeImage", randomCodeImage);

        return ResponseDto.success(map);

    }

    /**
     * 做登录操作
     *
     * @param phUserVO
     * @return
     */
    @PostMapping("doLogin")
    public ResponseDto userLogin(@RequestBody UserVO phUserVO) {
        System.err.println(phUserVO);
        return userService.userLogin(phUserVO);
    }

    //  这边是做用户注册
    @RequestMapping("resgit")
    public ResponseDto userRegister(@RequestBody UserVO phUserVO) {
        System.out.println(phUserVO);
        return userService.userRegister(phUserVO);
    }

    //  这边是做头像修改
    @RequestMapping("updateImage")
    public ResponseDto updateImage(@RequestParam("UserId") Integer userId, @RequestParam("image") String image) {
        return userService.updateImage(userId, image);
    }

    //    获取所有的地址信息
    @RequestMapping("getAllAddress")
    public ResponseDto getAllAddress(@RequestBody productPageVO productPageVO) {
        System.err.println(productPageVO);
        return userService.getAllAddress(productPageVO);
    }

    //  这边是修改地址
    @RequestMapping("updateAddress")
    public ResponseDto updateAddress(@RequestBody SnackAddress snackAddress) {
        System.err.println(snackAddress);
        return userService.updateAddress(snackAddress);
    }

    // 删除地址信息
    @RequestMapping("deleteAddress")
    public ResponseDto deleteAddress(@RequestParam("id") Integer id) {
        return userService.deleteAddress(id);
    }

    // 这边是做添加用户地址信息
    @RequestMapping("addAddress")
    public ResponseDto addAddress(@RequestBody SnackAddress snackAddress) {
        System.err.println(snackAddress);
        return userService.addAddress(snackAddress);
    }

    @RequestMapping("getAlluserMessage")
    public ResponseDto getAlluserMessage(@RequestParam("id") Integer id) {
        return userService.getAlluserMessage(id);
    }

    /**
     * 充值
     *
     * @param id
     * @param money
     * @return
     */
    @RequestMapping("recharge")
    public ResponseDto recharge(@RequestParam("id") Integer id, @RequestParam("money") double money) {
        return userService.recharge(id, money);
    }
}